$(document).ready(function () {
    initEvent();
});

function initEvent() {
    $("#input").on("change keyup", function() {
        $("#time").html("");
        var start = new Date().getTime();
        reload();
        var end = new Date().getTime();
        $("#time").html("耗时： " + (end - start) + " ms");
    });
}

function reload() {
    var input = $("#input").val();
    if (!input) {
        return false;
    }
    $.ajax({
        url: "/demo/analyze",
        data: JSON.stringify({"input": input}),
        contentType: "application/json",
        dataType: "json",
        async: false,
        type: "POST",
        success: function (data) {
            var values = data.data;
            $("#result").html("");
            for (var value in values) {
                $("#result").append(values[value] + "</br>");
            }
        },
        error: function (msg) {
            alert(msg);
        }
    });
}